/****************************************************************************
*                                                                           *
* drawmanager.h -- template state implementation		                    *
*                                                                           *
* ALaRI 2008												                *
*                                                                           *
****************************************************************************/
#pragma once

#if !defined(__DRAWMANAGER_H)
#define __DRAWMANAGER_H

#include "../../common/defs.h"
#include "../../common/singleton.h"
#include "drawshape.h"

#include <QObject>
#include <QEvent>
#include <QPaintDevice>
#include <QPainter>
#include <QString>
#include <QImage>
#include <QList>
#include <QPoint>

class CDrawState;
class CSensorPoint;

class CDrawManager : public QObject
{
	Q_OBJECT

	friend class CDrawState;
	friend class CFloorPlan;

public :
	/****************************************************************************
	* Construction/Destruction													*
	****************************************************************************/
	CDrawManager(QPaintDevice *pPaintDevice, int& nWidth, int& nHeight);
	~CDrawManager();
	/****************************************************************************
	* Public interface															*
	****************************************************************************/
	QImage getImage() const; 

	void drawDemo();
	void reset(); 
	void redraw(QRegion &redrawRegion);
	
	void processEvent(QEvent *pEvent);

	void startDrawRect();
	void startDrawEllipse();
	void startDrawLine();
	void startIdle();
	void startDrawPoint();
	void selectShape(const QPoint& rPoint);
	void addShape(CDrawShape *pShape);
	void addShape(const QPoint& qPointFrom, const QPoint& qPointTo, int nType);

	void reshape(QPoint& rPoint, int nIndex = -1); 

	inline void setBackgroundColor(const QColor &rColor) { m_colorBackground = rColor;}

	inline int getPenWidth() { return m_pen.width(); }
	inline QColor getPenColor() { return m_pen.color(); }

	// TODO 
	inline bool hasImageChanged() { return m_bImageChanged; }
	inline bool setImageChanged(bool bChanged) { return m_bImageChanged = bChanged; }

public slots:
	void setPenColor(const QColor& rColor) { m_pen.setColor(rColor);}
	void setPenWidth(int nWidth) {	m_pen.setWidth(nWidth); }
	void deleteCurrentShape();

signals:
	void updated();
	void pointAddedOrRemoved(CSensorPoint*, bool);

protected :
	void changeState(CDrawState *pDrawState);
	void removeAllShapes();

private :
	/****************************************************************************
	* Private helpers															*
	****************************************************************************/
	int indexOfShape(QString &strName) const;
	QString uniqueShapeName(QString strName);
	/****************************************************************************
	* Private data																*
	****************************************************************************/
	QList<CDrawShape *>	m_qListShape;	 
	// drawing state
	CDrawState		*m_pDrawState;
	// paint device
	QPaintDevice	*m_pPaintDevice;
	// draw shape
	CDrawShape		*m_pSelectedShape;
	// size
	const int&		m_nWidth;
	const int&		m_nHeight;

	bool			m_bImageChanged;
	QColor			m_colorBackground;
	QPen			m_pen;
};

class CSensorPoint : public CDrawPoint
{
	virtual ~CSensorPoint() = 0;
};

#endif /* __DRAWMANAGER_H */
/****************************************************************************
* End of file																*
****************************************************************************/
